package com.yxuan.springboot.controller;

import com.yxuan.springboot.service.AllProfessionalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import com.yxuan.springboot.model.AllProfessional;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 
 * @author zchao
 *   AllProfessional控制器
 * @date 2023-05-18 20:19:29
 */
@Controller
@Api(tags = "全国专业信息")
@RequestMapping(value = "/allprofessional", method = {RequestMethod.POST,RequestMethod.GET})
@CacheConfig(cacheNames = "allprofessional")//缓存名，和管理器中配置的一致
public class AllProfessionalController extends BaseController<AllProfessional>{
	
    @Autowired
    private AllProfessionalService allProfessionalService;
    /**
     *  查询专业类别信息和大致专业信息
     */
    @ApiOperation(value = "查询专业类别信息和大致专业信息", notes = "查询专业类别信息和大致专业信息")
    @RequestMapping("/loadAllProfessionalMajor")
    @ResponseBody
    @Cacheable(key = "'Major-' + #educationLevel",unless = "#result==null", condition = "#educationLevel!=null")//#result返回结果
    public Map<String, Object> loadAllProfessionalMajor(String educationLevel){
        return allProfessionalService.findAllProfessionalMajor(educationLevel);
    }

    //根据条件（无条件）查询多个结果
    @ApiOperation(value = "根据条件（无条件）--查询多个结果---", notes = "根据条件（无条件）--查询多个结果--",httpMethod = "GET")
    @RequestMapping("/loadManyByPramas")
    @ResponseBody
    @Cacheable(key = "'loadManyByPramas-' + #t",unless = "#result==null", condition = "#t!=null")//#result返回结果
    public List<AllProfessional> loadManyByPramas(AllProfessional t) {
        try {
            return allProfessionalService.findManyByPramas(t);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 根据条件查询单个结果
     *
     */
    @ApiOperation(value = "根据条件查询单个数据", notes = "根据条件查询单个数据",httpMethod = "GET")
    @RequestMapping("/loadObjectByPramas")
    @ResponseBody
    @Cacheable(key = "'professionalloadObjectByPramas-' + #t",
            unless = "#result==null",
            condition = "#t!=null")//#result返回结果
    public AllProfessional loadObjectByPramas(AllProfessional t){
        try {
            return allProfessionalService.findObjectByPramas(t);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
